﻿namespace HomeworkOppPartOne
{
    using System;

    class CallHistory
    {
        private const decimal price = 0.37m;
        internal static void CallHistoryTest()
        {

            MobilePhone phone = new MobilePhone("Nexus 4", "Google", 250, "Tonny Stark",
                         new Battery("LG2100", 40, 40, BatteryType.LiIon),
                         new Display(4.7, 16000000));
            while (true)
            {
                Console.WriteLine("Do you want to place a call? Press 1 for YES, 0 for NO");
                int choice = int.Parse(Console.ReadLine());
                if (choice == 1)
                {
                    Console.WriteLine("What is the phone number?");
                    string number = Console.ReadLine();
                    Console.WriteLine("What is the duration?");
                    int duration = int.Parse(Console.ReadLine());

                    phone.IncommingCall(number, duration);
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine("\nCall history:");
            foreach (var call in phone.CallHistory)
            {
                Console.WriteLine(call);
            }
            Console.WriteLine();

            Console.WriteLine("Total price of the calls is {0:F2}", phone.CurrentFacture(price));
            Console.WriteLine();

            try
            {
                phone.LongestCallRemove();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine("Total price of the calls after removing the longest call is {0:F2}", phone.CurrentFacture(price));

            Console.WriteLine("\nCall history:");
            phone.ClearHistory();
            if (phone.CallHistory.Count == 0)
            {
                Console.WriteLine("The call history is empty");
            }
            else
            {
                foreach (var call in phone.CallHistory)
                {
                    Console.WriteLine(call);
                }
            }
        }
    }
}